import { Point } from "./point";
import { fromLonLat } from "ol/proj";
import { Polygon } from "ol/geom";
import { Feature } from "ol";
import { Fill, Stroke, Style } from "ol/style";

export class MapDraw {

	private static polygonFillColor = 'rgba(50, 138, 288, 0.3)';
	private static polygonStrokeColor = 'rgba(0, 90, 200, 1)';

	/** 新建多边形Feature */
	public static createPolygonFeature(points: Array<Point>): Feature<Polygon> {
		let pts = [];
		for (let i = 0; i < points.length; i++) {
			pts.push(fromLonLat([points[i].lng, points[i].lat]));
		}
		let polygon = new Polygon([pts]);
		let feature = new Feature({ geometry: polygon });
		let style = new Style({
			stroke: new Stroke({
				color: this.polygonStrokeColor,
				width: 3
			}),
			fill: new Fill({
				color: this.polygonFillColor,
			}),
		});
		feature.setStyle(style);
		return feature;
	}

}
